home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_05 / pugh / pugh01.lst < prev   
Encoding:
File List  |  1994-03-01  |  596 b   |  38 lines

  1. #include <stdlib.h>
  2.  
  3. class A
  4.     {
  5. private:
  6. struct DataType
  7.     {
  8.     double x, y;
  9.     } *data;
  10.     int size;
  11. public:
  12.     A();
  13.     A(int n, double *x, double *y);
  14.     sort();
  15.     }
  16.  
  17. A::A() { } // Code Omitted
  18.  
  19. A::A(int n, double *x, double *y) { }   // Code Omitted
  20.  
  21.  
  22. A::sort()
  23.     {
  24.     qsort(data, size, sizeof(DataType), compare_function);
  25.     }
  26.  
  27. int compare_function(const void *a, const void *b)
  28.     {
  29.     const DataType *first = (DataType *) a;
  30.     const DataType *second = (DataType *) b;
  31.     if ( first->x > second->x )
  32.     return -1;
  33.     else if ( first->x < second->x )
  34.         return 1;
  35.     else
  36.         return 0;
  37.     }
  38.